package cn.mln521.test;

import cn.mln521.ioc.demo3.Man;
import cn.mln521.ioc.demo3.Person;
import cn.mln521.ioc.demo3.Student;
import cn.mln521.ioc.demo4.UserDao;
import cn.mln521.ioc.demo5.Product;
import cn.mln521.ioc.demo5.User;
import cn.mln521.ioc.demo5.User2;
import cn.mln521.ioc.demo6.CollectionBean;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Spring属性注入
 */
public class SpringDemo5 {

    /**
     * 构造方法注入
     */
    @Test
    public void demo1() {
        ApplicationContext context = new ClassPathXmlApplicationContext("application.xml");
        User user = (User) context.getBean("user");
        System.out.println(user);
    }

    /**
     * setter方法注入 && p命名空间注入
     */
    @Test
    public void demo2() {
        ApplicationContext context = new ClassPathXmlApplicationContext("application.xml");
        User2 user2 = (User2) context.getBean("user2");
        System.out.println(user2);
    }

    /**
     * setter方法注入 SpEL注入
     */
    @Test
    public void demo3() {
        ApplicationContext context = new ClassPathXmlApplicationContext("application.xml");
        Product product = (Product) context.getBean("product");
        System.out.println(product);
    }

    /**
     * 复杂类型的 collectionBean
     */
    @Test
    public void demo4() {
        ApplicationContext context = new ClassPathXmlApplicationContext("application.xml");
        CollectionBean collectionBean = (CollectionBean) context.getBean("collectionBean");
        System.out.println(collectionBean);
    }
}
